Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

add KV Table iterator bool operator #987

Closed
wants to merge 8 commits into from

Conversation

vzqzhang
Copy link
Contributor

@vzqzhang vzqzhang commented Oct 27, 2020

Change Description

Added bool operator to KV table iterator so that developers can easily check if the iterator exists by using an if (itr) {} statement.

Change Type

Select ONE

  • Documentation
  • Stability bug fix
  • Other
  • Other - special case

Consensus Changes

  • Consensus Changes

API Changes

  • API Changes

Documentation Additions

  • Documentation Additions

libraries/eosiolib/contracts/eosio/key_value.hpp Outdated Show resolved Hide resolved
libraries/eosiolib/contracts/eosio/key_value.hpp Outdated Show resolved Hide resolved
@@ -462,6 +462,8 @@ namespace internal {
return eosio::key_type{(char*)buffer, actual_value_size};
}

bool valid() const { return itr_stat != status::iterator_erased; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be itr_stat == status::iterator_ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the iterator end() be true or false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be itr_stat == status::iterator_ok?

Updated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

False. You can't materialize the value from either erased or end.

So the use case for this is:

auto itr = find some value
if (itr)
   do something with the value
else
   create an entry for the key and value

@vzqzhang vzqzhang mentioned this pull request Nov 10, 2020
7 tasks
@vzqzhang
Copy link
Contributor Author

Since CI fixes are required for buildkite build, I created a new PR: #997

@vzqzhang vzqzhang closed this Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants